package com.lucweb.action;


import com.lucweb.entity.BaseDict;
import com.lucweb.entity.TaskOther;
import com.lucweb.service.BaseDictService;
import com.lucweb.service.OtherService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.List;

@Controller("otherAction")
@Scope("prototype")
public class OtherAction extends ActionSupport{

    @Resource
    private OtherService otherService;

    @Resource
    private BaseDictService baseDictService;




    private TaskOther taskOther;

    private int taskId;

    //新建接电窗口
    public String newOther(){

        //没有id时设置id
        int bid = otherService.getmaxId();

        List<BaseDict> nameList=baseDictService.getListByTypeCode("3");
        List<BaseDict>companyList=baseDictService.getListByTypeCode("2");

        ActionContext.getContext().put("nameList",nameList);
        ActionContext.getContext().put("bid",bid);
        ActionContext.getContext().put("companyList",companyList);


        return "Others";

    }

    //修改接电
    public String editOther(){

        taskOther = otherService.gettaskOtherById(taskId);

        ActionContext.getContext().put("taskOther", taskOther);

        List<BaseDict>nameList=baseDictService.getListByTypeCode("3");
        List<BaseDict>companyList=baseDictService.getListByTypeCode("2");

        ActionContext.getContext().put("nameList",nameList);
        ActionContext.getContext().put("companyList",companyList);




        System.out.println(taskOther);



        return "Others";

    }

    //删除接电
    public String deleteOther(){

        otherService.deleteOthertask(taskId);

        //刷新页面
        List<TaskOther>OtherList=otherService.showOther();
        ActionContext.getContext().put("OtherList",OtherList);

        return "addOther";

    }

    //接电
    public String saveOrUpdate(){

        System.out.println(taskOther);


        //先保存
        otherService.saveOrUpdate(taskOther);

        //刷新页面
        List<TaskOther>OtherList=otherService.showOther();
        ActionContext.getContext().put("OtherList",OtherList);

        return "addOther";

    }

    //获取接电列表
    public String Othershow(){


        List<TaskOther>OtherList=otherService.showOther();
        ActionContext.getContext().put("OtherList",OtherList);

        return "addOther";

    }

    public TaskOther getTaskOther() {
        return taskOther;
    }

    public void setTaskOther(TaskOther taskOther) {
        this.taskOther = taskOther;
    }


    public int getTaskId() {
        return taskId;
    }

    public void setTaskId(int taskId) {
        this.taskId = taskId;
    }


}
